﻿#region FileHeader
//////////////////////////////////////////////////////////////////////////////////
// Author:                          Hector Llanos
// Date:                            08.27.2010
// FileName:                        CNetworkConnectState.cs
// Reason:                          determine single player / multiplayer
//////////////////////////////////////////////////////////////////////////////////
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Run_Game;

namespace GameState
{
    public class CNetworkConnectState : IGameState
    {
        private ContentManager m_pContent;
        private SpriteBatch m_pSpriteBatch;
        private int m_nSelection;

        private const int MAXITEMS = 2;
        private KeyboardState oldState;
        private SpriteFont m_MainSprite;

        public void Enter(ContentManager content, SpriteBatch spriteBatch)
        {
            m_pContent = content;
            m_pSpriteBatch = spriteBatch;

            m_MainSprite = content.Load<SpriteFont>("Fonts/ARCADECLASSIC");

            oldState = Keyboard.GetState();
        }
        public void Input()
        {
            KeyboardState newState = Keyboard.GetState();

            // Is the UP key down?
            if (newState.IsKeyDown(Keys.Up))
            {
                if (!oldState.IsKeyDown(Keys.Up))
                {
                    m_nSelection--;

                    if (m_nSelection < 0)
                        m_nSelection = MAXITEMS - 1;
                }
            }

            // Is the down key down?
            if (newState.IsKeyDown(Keys.Down))
            {
                if (!oldState.IsKeyDown(Keys.Down))
                {
                    m_nSelection++;

                    if (m_nSelection >= MAXITEMS)
                        m_nSelection = 0;
                }
            }
            // Is the ENTER key down?
            if (newState.IsKeyDown(Keys.Enter))
            {
                if (!oldState.IsKeyDown(Keys.Enter))
                {
                    switch (m_nSelection)
                    {
                        default:
                        case 0:
                            {
                                Game1.Instance.ChangeState(new CCharacterSelectState());
                                //Game1.Instance.PushState(new CHudState());
                                break;
                            }
                        case 1:
                            Game1.Instance.ChangeState(new CNetworkSetupState());
                            break;
                        //case 2:
                        //    Game1.Instance.ChangeState(new CreditState());
                        //    break;
                        //case 3:
                        //    Game1.Instance.Exit();
                        //    break;
                        //break;
                    }
                }
            }

            // Update saved state.
            oldState = newState;

        }
        public void Update(TimeSpan fElapsedTime)
        {

        }
        public void Render()
        {
            string textToRender = "Network Session";

            // Find the center of the string
            Vector2 FontOrigin = m_MainSprite.MeasureString(textToRender) / 2;

            //draw main menu
            m_pSpriteBatch.DrawString(m_MainSprite, textToRender, new Vector2(Game1.Instance.Graphics.PreferredBackBufferWidth / 2, 200), Color.Red, 0, FontOrigin, 1.5f, SpriteEffects.None, 0.5f);


            // Draw the play game string
            textToRender = "Single Player";
            FontOrigin = m_MainSprite.MeasureString(textToRender) / 2;

            if (m_nSelection == 0)
                m_pSpriteBatch.DrawString(m_MainSprite, textToRender, new Vector2(600, 570), Color.Red, 0, FontOrigin, 1.5f, SpriteEffects.None, 0.5f);
            else
                m_pSpriteBatch.DrawString(m_MainSprite, textToRender, new Vector2(600, 570), Color.White, 0, FontOrigin, 1.5f, SpriteEffects.None, 0.5f);

            // instruction
            textToRender = "Network Session";
            FontOrigin = m_MainSprite.MeasureString(textToRender) / 2;
            if (m_nSelection == 1)
                m_pSpriteBatch.DrawString(m_MainSprite, textToRender, new Vector2(600, 605), Color.Green, 0, FontOrigin, 1.5f, SpriteEffects.None, 0.5f);
            else
                m_pSpriteBatch.DrawString(m_MainSprite, textToRender, new Vector2(600, 605), Color.White, 0, FontOrigin, 1.5f, SpriteEffects.None, 0.5f);

        }
        public void Exit()
        {

        }
    }
}
